Skip to content

fix: improve jump_search - precompute sqrt, add tests, modernize C++#3169

Open
https-hari wants to merge 1 commit into
TheAlgorithms:masterfrom
https-hari:improve/jump-search-optimization
Open

fix: improve jump_search - precompute sqrt, add tests, modernize C++#3169
https-hari wants to merge 1 commit into
TheAlgorithms:masterfrom
https-hari:improve/jump-search-optimization

Conversation

@https-hari

Copy link
Copy Markdown

Description of Change

Improved the existing jump_search.cpp implementation:

  • Precomputed sqrt(n) once before the loop instead of recomputing
    on every iteration — avoids repeated floating point operations
  • Replaced raw int[] array with std::vector<int> (modern C++)
  • Used static_cast<int> for float-to-int conversion (safer than implicit cast)
  • Added complete Doxygen documentation (\brief, \param, \returns)
  • Added self-test suite covering:
    • Element in middle
    • First element
    • Last element
    • Element not present
    • Below range
    • Single element array
    • Empty array

Time complexity: O(sqrt(n)) — unchanged
Space complexity: O(1) — unchanged

Relates to #2456

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Author has not responded to the comments for over 2 weeks label Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Author has not responded to the comments for over 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant